$(function() {
    videoInit.call("#videoParents");
    AOS.init();
    var mySwiper = new Swiper('.swiper-container', {
        slidesPerView: 1.44,
        spaceBetween: 12,
        centeredSlides: true,
        loop: true,
        on: {
            transitionEnd: function() {
                var index1 = $('.swiper-slide').eq(this.activeIndex).data("index");
                $('.slide-title').each(function() {
                    $(this).css('opacity', '0');
                })
                $('.slide-title[data-index=' + index1 + ']').css('opacity', '1');
            }
        }
    });
    var mySwiper = new Swiper('.company-swiper', {
        slidesPerView: 1.44,
        centeredSlides: true,
        loop: true
    });

    var $scrollBox = $('#scrollbox');
    $('#scrollbox-goTop').click(function() {
        $("html,body").animate({
            scrollTop: 0
        }, 300);
    });
    $(document).scroll(function() {
        var top = $(this).scrollTop();
        if (top >= window.screen.height) {
            $scrollBox.show();
        } else {
            $scrollBox.hide();
        }
    });
});

function videoInit() {
    if (typeof videojs != 'function') {
        return false;
    }
    window.player = videojs("#videoPlayer", {
        autoplay: false,
        controls: true,
        muted: false,
        preload: 'metadata',

        width: this.width,

        aspectRatio: "16:9"
    }, function() {

        var _height = $(".vjs-control-bar").css("height");
        $(".preview-pic").css("bottom", _height);
        this.on("play", function() {
            $(".preview-pic").hide();
        })

        this.on('ended', function() {
            $(".preview-pic").show();
            if (this.isFullscreen()) {

                player.exitFullscreen();
            }
        });
    });
}

function getParameters(paramName) {
    var returnValue = "";
    var kv = location.search.slice(1).split("&");
    for (var i = 0; i < kv.length; i++) {
        var index = kv[i].indexOf("=");
        if (index == -1) {
            continue;
        }
        var groupParam = kv[i].split("=")
        if (groupParam[0] == paramName) {
            if (returnValue.length > 0) {
                returnValue = returnValue + "|" + groupParam[1];
            } else {
                returnValue = groupParam[1];
            }
        }
    }
    return returnValue;
}

(function() {
    var locationUrl = location.href;
    var refererUrl = document.referrer;
    if (locationUrl.length > 300) {
        locationUrl = locationUrl.substring(0, 300);
    }
    if (refererUrl.length > 200) {
        refererUrl = refererUrl.substring(0, 200);
    }
    var apiurl = "/huactrler/hm?lt=" + (+new Date()) + "&sid=" + getParameters('sid') + "&u_id=" + getParameters('u_id') + "&huaPid=" + getParameters('huaPid');
    apiurl = apiurl + "&url=" + encodeURIComponent(locationUrl) + "&urlreferer=" + encodeURIComponent(refererUrl);
    var img = new Image;
    img.onload = img.onerror = img.onabort = function() {}
    img.src = apiurl;
})();